program chapter6_3
    implicit none
    real r1,c1,r2,c2,l2,r3,l3,r4,c4
    complex i,iwantz
    complex z1,z2,z3,z4
    real omega,u,phase
    u=220

    print *,'input omega'
    read(*, *) omega
    print *, 'input r1,c1'
    read (*,*) r1,c1
    print *, 'input r2,c2,l2'
    read (*,*) r2,c2,l2
    print *, 'input r3,l3'
    read (*,*) r3,l3
    print *, 'input r4,c4'
    read (*,*) r4,c4

    z1=cmplx(r1,-1/(omega*c1))
    z2=cmplx(r2,l2*omega-1/(omega*c2))
    z3=cmplx(r3,omega*l3)
    z4=cmplx(r4,-1/(c4*omega))
    i=cmplx(u,0)/iwantz(z1,z2,z3,z4)
    print *, 'z in total=',iwantz(z1,z2,z3,z4)
    print *, 'I in total=', cmplx(u,0)/iwantz(z1,z2,z3,z4),'phase=',phase(i),'degree(s)'

end program

complex function iwantz(z1,z2,z3,z4)
    complex z1,z2,z3,z4
    complex z34,z234,z1234
    z34=(z3*z4)/(z3+z4)
    z234=z2+z34
    z1234=(z1*z234)/(z1+z234)
    iwantz=z1234
end function

real function phase(z)
    complex z
    phase=57.29578*atan2(aimag(z),real(z))
end function
